import book.Library;
import user.ProxyUser;
import user.User;
import user.factory.AdminUserFactory;
import user.factory.IUserFactory;
import user.factory.NormalUserFactory;

import java.util.Scanner;

public class LibrarySystem {
    public static void main(String[] args) {
        IUserFactory adminUserFactory = new AdminUserFactory();
        User admin = adminUserFactory.createUser("王大美",1);
        IUserFactory normalUserFactory = new NormalUserFactory();
        User normal1 = normalUserFactory.createUser("张三",2);
        User normal2 = normalUserFactory.createUser("李四",3);

        ProxyUser proxyUserAdmin = new ProxyUser(admin);
        ProxyUser proxyUserNormal1 = new ProxyUser(normal1);
        ProxyUser proxyUserNormal2 = new ProxyUser(normal2);

        //选择登录角色
        LibrarySystem librarySystem = new LibrarySystem();
        ProxyUser currentUser = librarySystem.selectProxyRole(proxyUserAdmin, proxyUserNormal1, proxyUserNormal2);
        //打印角色菜单
        while (true) {
            int choice = currentUser.display();
            //如何实现 选择几 (choice) 就执行哪个用户 (currentUser) 的哪个操作？
            //此时无需关心是 管理员还是普通用户，代理类会做权限判断
            currentUser.handleOperation(choice);
        }
    }

    public ProxyUser selectProxyRole(ProxyUser proxyUserAdmin, ProxyUser proxyUserNormal1, ProxyUser proxyUserNormal2) {
        System.out.println("选择角色进行登录：");
        System.out.println("1.管理员\n2.普通用户(张三)\n3.普通用户(李四)\n4.退出系统");
        ProxyUser currentUser = null;
        Scanner scanner = new Scanner(System.in);
        int choice = scanner.nextInt();
        switch (choice) {
            case 1:
                currentUser = proxyUserAdmin;
                break;
            case 2:
                currentUser = proxyUserNormal1;
                break;
            case 3:
                currentUser = proxyUserNormal2;
                break;
            case 4:
                System.out.println("系统已退出...");
                System.exit(0);
                break;
            default:
                break;
        }
        return currentUser;
    }
}
